package org.lq.ht.service.impl;

import java.util.ArrayList;
import java.util.List;

import javax.swing.JOptionPane;

import org.lq.ht.dao.impl.RoomDaoImpl;
import org.lq.ht.entity.Room;
import org.lq.ht.entity.TypeID;
import org.lq.ht.service.RoomService;
import org.lq.ht.util.CastUtils;
/**
 * 房间业务层实现
 *@author 张冲
 *@qq2865346830
 * @package org.lq.ht.service.impl
 * @date 2020年8月21日下午7:57:31
 */
public class RoomServiceImpl implements RoomService{
	RoomDaoImpl rd = new RoomDaoImpl();

	@Override
	public boolean saveRoom(Room t) {
		return rd.save(t)>0;
	}

	@Override
	public boolean updateRoom(Room t) {
		return rd.update(t)>0;
	}

	@Override
	public boolean deleteRoomById(int id) {
		return rd.delete(id)>0;
	}

	@Override
	public List<Room> findAll() {
		return rd.findAll();
	}

	@Override
	public Room getById(int id) {
		return rd.getById(id);
	}
	//TODO这里面的判断几条记录修改成功,几条失败修改失败记录,窗体展示失败修改的房间号,后续做
	public boolean saveRoomList(List<Room> list) {
		for (int i = 0; i < list.size(); i++) {
			Room r = list.get(i);
			if(!updateRoom(r)) {
				return false;
			}
		}
		return true ;
	}

	public List<Room> findByRoomType(TypeID t) {
		return rd.getByTypeID(t.getId());
	}
	@Override
	public List<Room> getByWays(String value,String content) {
		List<Room> list = null;
		if("全日房价".equals(value)) {
			//TODO房间价格有问题
			list = rd.getByRoomPrice(CastUtils.castDouble(content));
		}else if("客房号".equals(value)) {
			list = rd.getByRoomNumber(CastUtils.castInt(content));
		}else if("房间说明".equals(value)) {
			list = rd.getByRoomNote(content);
		}
		else {
//			list = rd.findAll();
		}
		return list;
	
}
}
